
#pragma once

using namespace System::Collections::Generic;
using namespace NUnit::Framework;

#include <ttg/services.h>
#include "CommonNodes.h"

namespace RuntimeLowTests
{
	namespace pipeline
	{
		[TestFixture]
		public ref class SimplePipeline
		{
			public:
				[Test]
				void OneNodePipeline()
				{
					ttg::services::ServiceBase::getRef()->start();
					Pipeline<int, int> *pl = new Pipeline<int, int>(wrap(new IncNode()));
					std::vector<int> res = pl->run(42);
					SAFE_DELETE(pl);
					ttg::services::ServiceBase::getRef()->stop();
					Assert::AreEqual(1, (int)res.size(), "Wrong count of results");
					Assert::AreEqual(43, (int)res[0], "Wrong increment: 42 + 1 != 43");
				}
				[Test]
				void OneNodeWithMultipleData()
				{
					//Preparing.
					ttg::services::ServiceBase::getRef()->start();
					Pipeline<int, int> *pl = new Pipeline<int, int>(wrap(new IncNode()));
					std::vector<int> data;
					for (size_t i = 0; i < 1024; i++)
						data.push_back(i);
					//Launching and testing.
					std::vector<int> res = pl->run(data);
					SAFE_DELETE(pl);
					ttg::services::ServiceBase::getRef()->stop();
					Assert::AreEqual(1024, (int)res.size(), "Wrong count of results");
					int sum = 0;
					for (size_t i = 0; i < 1024; i++)
						sum += res[i];
					Assert::AreEqual((1 + 1024) * 512, sum,
									 "Wrong increment: 1 + ... + 1024 != (1 + 1024) * 512");
				}
		};
	}
}